package auth

import (
	"github.com/gin-gonic/gin"
	logic2 "iot-base/auth/api/logic"
	"iot-base/auth/logger"
	types2 "iot-base/auth/types"
)

// EditUserGroup 编辑用户组.
func EditUserGroup(c *gin.Context) {
	requestId, _ := c.Get("RequestId")
	resp := types2.NewResult(c)
	var usesGroup types2.EditUsesGroup
	err := c.ShouldBind(&usesGroup)
	if err != nil {
		resp.ErrorCode(types2.ParamsError, "")
		return
	}
	logic := logic2.NewUserGroupLogic()
	err = logic.EditUserGroup(usesGroup.Uid, usesGroup.UserGroups)
	if err != nil {
		logger.Log.Errorf("[%v] err:=[%v]", requestId, err)
		resp.ErrorCode(types2.ExceptionError, err.Error())
	}
	resp.Success(gin.H{})
}

func FindUserGroup(c *gin.Context) {
	requestId, _ := c.Get("RequestId")
	var req types2.ReqGetUserGroup
	result := types2.NewResult(c)
	err := c.ShouldBind(&req)
	if err != nil {
		result.ErrorCode(types2.ParamsError, "")
		return
	}

	logic := logic2.NewUserGroupLogic()
	resp, err := logic.FindUserGroup(req.Uid)
	if err != nil {
		logger.Log.Errorf("[%v] err:=[%v]", requestId, err)
		result.ErrorCode(types2.ExceptionError, "")
	}
	result.Success(resp)
}
